/**
 * COPYRIGHT. Harry Wu 2011. ALL RIGHTS RESERVED.
 * Project: just-core
 * Author: Harry Wu <harrywu304@gmail.com>
 * Created On: Jun 19, 2011 2:25:47 PM
 *
 */
package org.justframework.api.connector;

import org.justframework.core.mapper.MapperFactory;
import org.justframework.util.JsonUtil;


/**
 * rest style response bean interface
 *
 */
public class Response {
	
	/**
	 * request id
	 */
	private String requestId;
	
	/**
	 * response content
	 */
	private Object content;
	
	/**
	 * client send request timestamp 
	 */
	private long requestTimestamp;	
	
	/**
	 * server receive request timestamp 
	 */
	private long receiveTimestamp;
	
	/**
	 * server to reply timestamp
	 */
	private long replyTimestamp;
	
	/**
	 * client get return timestamp
	 */
	private long returnTimestamp;
	
	private int errorCode;
	
	/**
	 * @param requestId the requestId to set
	 */
	public void setRequestId(String requestId) {
		this.requestId = requestId;
	}

	/**
	 * @return the requestId
	 */
	public String getRequestId() {
		return requestId;
	}

	public Object getContent() {
		return content;
	}
	
	public void setContent(Object content) {
		this.content = content;
	}
	
	public long getRequestTimestamp() {
		return requestTimestamp;
	}

	public void setRequestTimestamp(long requestTimestamp) {
		this.requestTimestamp = requestTimestamp;
	}

	public long getReceiveTimestamp() {
		return receiveTimestamp;
	}

	public void setReceiveTimestamp(long receiveTimestamp) {
		this.receiveTimestamp = receiveTimestamp;
	}

	public long getReplyTimestamp() {
		return replyTimestamp;
	}

	public void setReplyTimestamp(long replyTimestamp) {
		this.replyTimestamp = replyTimestamp;
	}

	public long getReturnTimestamp() {
		return returnTimestamp;
	}

	public void setReturnTimestamp(long returnTimestamp) {
		this.returnTimestamp = returnTimestamp;
	}
	
	/**
	 * @return the errorCode
	 */
	public int getErrorCode() {
		return errorCode;
	}

	/**
	 * @param errorCode the errorCode to set
	 */
	public void setErrorCode(int errorCode) {
		this.errorCode = errorCode;
	}

	@Override
	public String toString(){
		StringBuilder result = new StringBuilder();
		result.append("requestId:"+requestId).append(",");
		result.append("requestTimestamp:"+requestTimestamp).append(",");
		result.append("receiveTimestamp:"+receiveTimestamp).append(",");
		result.append("replyTimestamp:"+replyTimestamp).append(",");
		result.append("returnTimestamp:"+returnTimestamp).append(",");
		result.append("errorCode:"+errorCode).append(",");
		result.append("content:"+content).append(",");
		return result.toString();
	}
	
	public <T> T getContent(Class<T> klass) {
		return MapperFactory.getDefaultMapper().toBean((String)content, klass);
	}

}